
_xinstore_db_flash = function(){};
_xinstore_db_flash.prototype.type = "flash";
_xinstore_db_flash.prototype.store = null;
_xinstore_db_flash.prototype.name = "";
_xinstore_db_flash.prototype.xid = "xinstore_db_flash_storage_object";
_xinstore_db_flash.prototype.timerId = 0;

_xinstore_db_flash.prototype.test = function(){
    if( !swfobject ){
        return false;
    }
    var major = swfobject.getFlashPlayerVersion().major;
    if( major < 8 ){
        return false;
    }
    return true;
};

_xinstore_db_flash.prototype.init = function( name, cfg, onReady ){
    this.name = name;
    var obj = this;
    
    var div = document.createElement("div");
    div.setAttribute( "id", "div"+this.xid );
    document.body.appendChild( div );

    var swfurl = "XINStore.swf";
    if( cfg && cfg.swf ){
        swfurl = cfg.swf;
    }

    var swfVersionStr = "8.0.0";
    var xiSwfUrlStr = "expressInstall.swf";
    var flashvars = {};
    var params = {};
    params.allowScriptAccess = "always";
    params.allowfullscreen = "true";
    var attributes = {};
    attributes.id = this.xid;
    attributes.name = this.xid;
    swfobject.embedSWF(
      swfurl, "div"+this.xid,
      1, 1,
      swfVersionStr, xiSwfUrlStr, 
      flashvars, params, attributes );

    var obj = this;
    var flashReady = function(){
      var _store = document.getElementById( obj.xid );
      if( _store && _store.xGet && _store.xSet && _store.xRemove && _store.xClear ){
        window.clearInterval( obj.timerId );
        obj.store = _store;
        if( typeof(onReady) == "function" ){
          onReady();
        }
      }
    };
    this.timerId = setInterval( flashReady, 100 );
};

_xinstore_db_flash.prototype.get = function( key ){
    return this.store.xGet( this.name, key );
};
_xinstore_db_flash.prototype.set = function( key, value ){
    this.store.xSet( this.name, key, value );  
};
_xinstore_db_flash.prototype.remove = function( key ){
    this.store.xRemove( this.name, key );  
};
_xinstore_db_flash.prototype.clear = function(){
    this.store.xClear( this.name );
}


xinstore.db.flash = new _xinstore_db_flash();
xinstore.dbs.push( xinstore.db.flash );